import time

from selenium.webdriver.common.by import By

from BasePage.basepage import BasePage


class PageLogin(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        # self.img1= (By.ID, "com.tpshop.malls:id/welcome_bg")
        self.img_02 = (By.ID, 'com.tpshop.malls:id/start_img')
        self.mine_loc = (By.ID, "com.tpshop.malls:id/mine_tv")
        self.mine_img_loc = (By.ID, "com.tpshop.malls:id/head_img")
        self.username = (By.ID, "com.tpshop.malls:id/mobile_et")
        self.password = (By.ID, "com.tpshop.malls:id/pwd_et")
        self.agree = (By.ID, "com.tpshop.malls:id/agree_btn")
        self.login_btn = (By.ID, "com.tpshop.malls:id/login_tv")
        self.aa = (By.ID, "com.tpshop.malls:id/nick_name_tv")
        self.fail = (By.ID, "com.tpshop.malls:id/title_tv")

        self.toast = (By.XPATH, "//android.widget.Toast")

    def login(self, username, password):
        time.sleep(3)
        for i in range(3):
            self.driver.swipe(1340, 1250, 100, 1250)
        self.click_element(self.img_02)
        self.click_element(self.mine_loc)
        self.click_element(self.mine_img_loc)
        self.base_clear_input(self.username, username)
        self.base_clear_input(self.password, password)
        self.click_element(self.agree)
        self.click_element(self.login_btn)



    def assert_toast(self):
        time.sleep(3)
        toast = self.get_element(self.toast).text
        return toast
